import 'package:flutter/material.dart';

class NoBytesFound extends StatelessWidget {
  const NoBytesFound({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                children: [
                  TextSpan(
                      text: '(˚Δ˚)b\n',
                      style: TextStyle(fontSize: 38, color: Colors.grey)),
                  TextSpan(
                      text: 'No bytes found for the document...',
                      style: TextStyle(fontSize: 24, color: Colors.grey))
                ],
              ))
        ]);
  }
}

class NoUploading extends StatelessWidget {
  const NoUploading({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                children: [
                  TextSpan(
                      text: '\\(o_o)/\n\n',
                      style: TextStyle(fontSize: 38, color: Colors.grey)),
                  TextSpan(
                      text:
                          'Waiting for uploading.\nClick "Upload Document" button to upload document.',
                      style: TextStyle(fontSize: 16, color: Colors.grey))
                ],
              ))
        ]);
  }
}

class NoOcrResult extends StatelessWidget {
  const NoOcrResult({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                children: [
                  TextSpan(
                      text: '(˚Δ˚)b\n',
                      style: TextStyle(fontSize: 38, color: Colors.grey)),
                  TextSpan(
                      text:
                          'No OCR result found in database, please trigger OCR service...',
                      style: TextStyle(fontSize: 24, color: Colors.grey))
                ],
              ))
        ]);
  }
}

class NoDocSelect extends StatelessWidget {
  const NoDocSelect({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                children: [
                  TextSpan(
                      text: '(;-;)\n',
                      style: TextStyle(fontSize: 38, color: Colors.grey)),
                  TextSpan(
                      text: 'No doument selected...',
                      style: TextStyle(fontSize: 24, color: Colors.grey))
                ],
              ))
        ]);
  }
}

class NoPageSelect extends StatelessWidget {
  const NoPageSelect({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          RichText(
              textAlign: TextAlign.center,
              text: TextSpan(
                children: [
                  TextSpan(
                      text: '(:-:)\n',
                      style: TextStyle(fontSize: 38, color: Colors.grey)),
                  TextSpan(
                      text: 'No page selected...',
                      style: TextStyle(fontSize: 24, color: Colors.grey))
                ],
              ))
        ]);
  }
}

class WaitingAnimation extends StatefulWidget {
  const WaitingAnimation({super.key});

  @override
  State<WaitingAnimation> createState() => _WaitingAnimationState();
}

class _WaitingAnimationState extends State<WaitingAnimation>
    with SingleTickerProviderStateMixin {
  late AnimationController _turnController;

  @override
  void initState() {
    super.initState();

    _turnController = AnimationController(
      duration: const Duration(seconds: 3),
      vsync: this,
    )..repeat();
  }

  @override
  void dispose() {
    _turnController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => RotationTransition(
        turns: _turnController,
        child: const Icon(color: Colors.grey, Icons.hourglass_empty, size: 100),
      );
}

// class WaitingAnimation extends StatefulWidget {
//   const WaitingAnimation({super.key});

//   @override
//   State<WaitingAnimation> createState() => _WaitingAnimationState();
// }

// class _WaitingAnimationState extends State<WaitingAnimation>
//     with TickerProviderStateMixin {
//   late AnimationController _turnController;
//   late AnimationController _textController;
//   final String baseText = 'Please wait';

//   @override
//   void initState() {
//     super.initState();

//     _turnController = AnimationController(
//       duration: const Duration(seconds: 3),
//       vsync: this,
//     )..repeat();

//     _textController = AnimationController(
//       duration: const Duration(milliseconds: 800),
//       vsync: this,
//     )..repeat();
//   }

//   @override
//   void dispose() {
//     _turnController.dispose();
//     _textController.dispose();
//     super.dispose();
//   }

//   String _getAnimatedText() {
//     final progress = (_textController.value * 4).floor();
//     final dots = '.' * (progress % 4);
//     return '$baseText$dots';
//   }

//   @override
//   Widget build(BuildContext context) {
//     return Column(
//       mainAxisSize: MainAxisSize.max,
//       mainAxisAlignment: MainAxisAlignment.center,
//       children: [
//         RotationTransition(
//             turns: _turnController,
//             child: const Icon(
//                 color: Colors.grey, Icons.hourglass_empty, size: 100)),
//         const SizedBox(height: 20),
//         AnimatedBuilder(
//           animation: _textController,
//           builder: (context, child) => Text(
//             _getAnimatedText(),
//             style: const TextStyle(color: Colors.grey, fontSize: 18),
//           ),
//         ),
//       ],
//     );
//   }
// }

void waitingAnimDialog(BuildContext context) {
  if (ModalRoute.of(context)?.isCurrent != true) return;
  showDialog(
      context: context,
      barrierDismissible: false, // User can't dismiss by tapping outside
      barrierColor: Colors.black.withValues(alpha: .5),
      builder: (context) => const WaitingAnimation());
}
